package org.muyun.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class RequestController {

    @GetMapping("/goto")
    public String gotoPage(HttpServletRequest request){
        request.setAttribute("msg","成功了。。。。");
        request.setAttribute("code",200);
        return "forward:/success"; //转发到success请求
    }

    @ResponseBody
    @GetMapping("/success")
    public String success(@RequestAttribute("msg") String msg,
                          @RequestAttribute("code") Integer code,
                          HttpServletRequest request){
        Object attribute = request.getAttribute("msg");
        Object code1 = request.getAttribute("code");
        Map<String,Object> map = new HashMap<>();
        map.put("msg",msg);
        map.put("attribute",attribute);
        map.put("code",code1);
        System.out.println(map);
        return msg + code;
    }
}
